package my.jwds.p385;


import java.util.ArrayList;
import java.util.List;

// This is the interface that allows for creating nested lists.
// You should not implement it, or speculate about its implementation
public class NestedInteger {

    List<NestedInteger> list;
    Integer val;

    public NestedInteger() {

    }

    public NestedInteger(Integer val) {
        this.val = val;
    }


    public boolean isInteger() {
        return list == null;
    }


    public Integer getInteger() {
        return val;
    }


    public void setInteger(int value) {
        this.val = value;
    }


    public void add(NestedInteger ni) {
        if (list == null){
            list = new ArrayList<>();
        }
        list.add(ni);
    }


    public List<NestedInteger> getList() {
        return list;
    }
}
